package com.jurenzhao.partssystem.information.basic_series.controller;


import com.jurenzhao.partssystem.information.basic_series.util.PathImg;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.UUID;

@Controller
public class FileController {
	@RequestMapping("/show/{seriesPic}")
	public void show(HttpServletResponse response,
			@PathVariable("seriesPic") String seriesPic){
		File file = new File(PathImg.IMAGE_BASE_PATH + seriesPic);
		if(file!= null && file.exists()){
			byte [] buffer = new byte[1024];
			InputStream io = null;
			OutputStream os = null;
			try {
				os = response.getOutputStream();
				io = new FileInputStream(file);
				while(io.read(buffer) != -1){
					os.write(buffer);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}finally{
				try {
					if(io != null){
						io.close();
					}
					os.flush();
					os.close();
				} catch (Exception e2) {
					e2.printStackTrace();
				}
			}
		}
	}

}
